<?php

require_once dirname(__FILE__).'/../../../../test/bootstrap.php';
require_once dirname(__FILE__).'/../../../../lib/urCronServiceBase.class.php';
require_once dirname(__FILE__).'/../../lib/urCronServiceDiggHistory.class.php';

clear_database();
$t = new lime_test(6, new lime_output_color());

ini_set('user_agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; fr-fr) AppleWebKit/528.18.1 (KHTML, like Gecko) Version/4.0 Safari/528.17');

$diggFeed = new urCronFeed();
$diggFeed->setName("my digg history");
$diggFeed->setFeedUri('http://digg.com/users/MrBabyMan/history.rss');  // Digg most active user
$diggFeed->setClass("urCronServiceDiggHistory");
$diggFeed->save();

$diggService = new urCronServiceDiggHistory();
$diggService->setFeedId($diggFeed->getId());
$feedContent = file_get_contents($diggFeed->getFeedUri());
$diggService->setFeedUri(file_get_contents($diggFeed->getFeedUri()));

// ::getServiceName
$t->diag('::getServiceName()');
$t->is_deeply(urCronServiceDiggHistory::getServiceName(),
              array('Digg History', 'urCronServiceDiggHistory'),
             '::getServiceName() returns an array with a description associated with the class name.');


$t->diag('->doCronJob()');
$diggService->doCronJob();

$postCount = count($diggService->getFeed()->channel->item);
$items = Doctrine::getTable('urCronItem')->getItemsFromFeed($diggFeed->getId());
$t->isnt($items->count(), 0, 'Items have been inserted into the database');
